package com.example.controller;

import com.example.domain.AccidentRecord;
import com.example.service.AccidentRecordService;
import com.example.utils.AjaxResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

import static com.example.utils.AjaxResult.successData;

@RestController
@RequestMapping("/root")
public class AccidentRecordController {
    @Autowired
    private AccidentRecordService accidentRecordService;

    /** 缴费记录 */
    @RequestMapping("/accident")
    public AjaxResult accident(@RequestParam(defaultValue = "1", value = "page") Integer pageNum,
                               @RequestParam(defaultValue = "10", value = "limit") Integer pageSize,
                               @RequestParam(defaultValue = ""  , value = "accTime") String usr
    ){
        HashMap<String, Object> map = new HashMap<>();
        PageHelper.startPage(pageNum,pageSize);
        if (usr == null || usr.equals("")) {
            map.put("usr","");
            List<AccidentRecord> accidentRecords = accidentRecordService.listAll(map);
            PageInfo<AccidentRecord> page = new PageInfo<>(accidentRecords);
            return successData(page.getTotal(), accidentRecords);
        }
        map.put("usr",usr);
        List<AccidentRecord> accidentRecords = accidentRecordService.listAll(map);
        PageInfo<AccidentRecord> page = new PageInfo<>(accidentRecords);
        return successData(page.getTotal(), accidentRecords);
    }
}
